using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using BO.Admin;
using System.Web.SessionState;

namespace Admin.uploadify
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Upload : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //if (!User_Helper.IsLoggedIn(context)) context.Response.Redirect("/Login.aspx");
            HttpPostedFile file = context.Request.Files["Filedata"];
            string folder = System.Web.HttpContext.Current.Server.MapPath(context.Request["folder"]);
            string targetDirectory = folder;
            string targetFilePath = Path.Combine(targetDirectory, file.FileName);

            // Uncomment the following line if you want to make the directory if it doesn't exist
            //if (!Directory.Exists(targetDirectory)) Directory.CreateDirectory(targetDirectory);

            file.SaveAs(targetFilePath);

            context.Response.Write("1");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
